#ifndef SERIALTHREAD_H
#define SERIALTHREAD_H

#include <QMutex>
#include <QObject>
#include <QSerialPort>
#include <QThread>

class SerialThread : public QObject
{
    Q_OBJECT
public:
    explicit SerialThread( const QString &deviceName, QObject *parent = nullptr );
    ~SerialThread();

    void open();

    void close();

    bool isOpen() const;

signals:
    void sigOpenStateChanged( bool &open );

    void sigOpenSerial();
    void sigCloseSerial();

public slots:
    void onOpenSerial();
    void onCloseSerial();


private slots:
    void doSomething();
    void onReadyRead();

private:
    std::atomic<bool>           _is_open;
    QMutex                      _mutex;
    QString                     _device_name;
    QScopedPointer<QSerialPort> _serial_port;
    QThread                     _thread;
};

#endif  // SERIALTHREAD_H
